home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
Yerk 3.6.7
/
yerk 367
/
tool+
/
popUp6
< prev
next >
Wrap
Text File
|
1994-11-29
|
6KB
|
155 lines
\ pmenu knows how to popup when asked, and it keeps track of
\ which item was selected, and it allows for an x,y offset
\ for display purposes
:CLASS pmenu <super hmenu
int type \ 0: 'offset' rel to mouse;1: use 'offset' as absolute
point offset \ if type=0, then MOUSE will be offset from upper left
\ corner of menu.
int lastPick \ refers to item number (starting from 1)
\ determines if popup appears offset to mouse, or at absolute position
:M type: ( n --) put: type ;M
:M popup: ( -- )
0 get: mHndl
get: type
IF int: offset l->g intSwap
ELSE where: fevent unpack gety: offset - swap getx: offset - pack
THEN
int: lastpick call popupmenuselect
unpack -> menuId -> mitem
mitem 0 >
IF get: resid menuId = \ is mouse in popUp?
IF mitem put: lastPick mitem exec: self \ yes
ELSE mitem menuId exec: menubar \ must be hierarchical submenu
THEN
ELSE 0 -> menuid
THEN ;M
\ this is coded to allow for getting the text item of a hierarchical menu
\ attached to the popup
:M getText: ( item# -- addr len)
0 menuId makeInt call getMHandle \ get menuhandle
swap makeint buf255 +base call GetItem \ get text of selected item
buf255 count ;M
:M offset: ( x y -- ) put: offset ;M
\ :M position: ( x y -- ) put: self ;M
:M putitem: ( lastPick -- ) put: lastPick ;M
:M getitem: ( -- lastPick ) get: lastPick ;M
:M getHItemName: ( -- addr len) get: lastPick getText: self ;M
\ inits to relative offset to mouse
:M classinit: 25 9 offset: self classinit: super ;M
;CLASS
\ stringvar - class of strings which are kept in memory
\ as barrays and have a max length - from mh
\ 5.24.89 rfl twidth and type replaces stringwidth and drawstring
\ inset rect before print and changed 2 to 1 in justification
\ 12.4.89 rfl a few modifications cosmetic
\ 5.24.90 rfl redid justinbox stuff to shorten code
\ 7.12.92 rfl deleted stringvar class
\ 5.20.93 rfl removed cursor stuff
\ 8.4.93 rfl mitem now points to text (from 1 not zero)...compatible with new pMenu fix. PROPOGATES
\ 10.20.93 rfl fixed exec: to not exec if no item was selected
\ 3.3.94 rfl set: window for print: also
\ 4.26.94 rfl uncommented in firstName:
\ Bitmap class for drawing bitmaps to screen
:CLASS bMap <Super warray
Var BaseAddr
Int RowBytes
Rect BndsRect
rect DestRect
\ ( n l t r b -- )
:M INIT: Put: bndsRect Put: RowBytes ;M
:M putDest: { x y \ x0 y0 -- } size: BndsRect -> y0 -> x0
x y x0 x + y0 y + put: destRect ;M
:M draw: idxbase +base Put: BaseAddr
abs: self portBit: actw
abs: BndsRect abs: destRect
word0 0 call copyBits ;M
:M offset: ( dx dy -- ) offset: destrect ;M
:M moveto: ( x y -- ) putDest: self draw: self ;M
;CLASS
5 bmap darrow \ instantiate a global down pointing arrow
hex
$ ff80 $ 7f00 $ 3e00 $ 1c00 $ 0800 put: darrow
decimal
2 0 0 9 5 init: darrow
\ draw text string justified in a given rectangle
: ctextbox { addr len arect just -- }
addr +base len aRect +base just makeint call textbox ;
\ definition of class that handles popup menus
\ popupRect provides a way to use pmenu
\ two kinds of disp/print are supported:
\ display a fixed name string or
\ display the last selected item in menu
:CLASS popUpMenu <super pMenu
int dmode \ display mode: ITEM (0) or NAME (1)
var myAction \ Menu has an action independent of item handler
var myWindow \ owning window
33 bytes name \ string holds name of rect...limited to 32 characters
int txFont \ retains its type of font
int txSize
int txFace
int txJust \ justification left(0), center(1), right(-1)
rect myBorder \ rectangle framing menu
:M placeDarrow: getBotX: myBorder
13 - size: myBorder swap drop 2/ getTopY: myBorder + 2- putDest: darrow ;M
\ *** initializing methods ***
:M font: ( font size face -- ) put: txFace put: txSize put: txFont ;M
:M justify: put: txJust ;M
:M actions: put: myAction ;M
:M putWindow: put: myWindow ;M
:M setMode: ( displayMode -- ) put: dmode ;M
:M putRect: ( l t r b -- ) put: myBorder placeDarrow: self
getTop: myBorder offset: self ;M
:M initFont: pushPort set: [ obj: myWindow ]
get: txFont tfont get: txSize tsize get: txFace tface popPort ;M
:M getRect: ( -- topx topy botx boty ) get: myBorder ;M
:M name: ( addr len -- ) dup 32 > classerr" 133 addr: name >str255 drop ;M
:M getName: ( -- addr len ) addr: name count ;M
:M print: ( -- ) pushPort actw obj: myWindow -> actw set: actw
2 1 inset: myBorder getBotX: myBorder dup 10 - putBotX: myBorder
1 tmode initFont: self
getName: self addr: myBorder get: txJust ctextBox
putBotX: myBorder -2 -1 inset: myBorder placeDarrow: self draw: darrow
-> actw popPort ;M
:M draw: ( -- ) pushPort set: [ obj: myWindow ]
1 1 offset: myBorder draw: myBorder
-1 -1 offset: myBorder clear: myBorder draw: myBorder print: self popPort ;M
:M ptIn: ( point --) ptIn: myBorder ;M
:M exec: ( -- ) where: theMouse pack ptin: self
IF popup: self
mitem 0> \ don't do anything if no item selected
IF get: dmode 0=
I